package edu.gdkm.dao;

import edu.gdkm.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderDAO {
    @Select("select * from tb_order where id = #{id}")
    @Results(id = "orderMap", value = {
            @Result(property = "user", column = "user_id", one = @One(select = "edu.gdkm.dao.UserDAO.findById"))
    })
    Order findById(Integer id);
    @Select("select * from tb_order")
    @ResultMap("orderMap")
    List<Order> findAll();
    @Select("select * from tb_order where user_id = #{userId}")
    List<Order> findByUserId(Integer userId);
    @Insert("insert into tb_order(number, user_id) values(#{number}, #{user.id})")
    boolean save(Order order);
    @Update("update tb_order set number = #{number}, user_id = #{user.id} where id = #{id}")
    boolean update(Order order);
    @Delete("delete from tb_order where id = #{id}")
    boolean delete(Integer id);
}
